package com.mini.game.global;

import com.mini.common.constant.CommonErrorCode;
import com.mini.common.util.JacksonUtil;
import com.mini.common.vo.ResData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionAdvice {
    private final static Logger logger = LoggerFactory.getLogger(GlobalExceptionAdvice.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public String handleHttpException(HttpServletRequest req, Exception ex) {
        logger.error(ex.getMessage(), ex);
        return JacksonUtil.toJsonString(ResData.buildErrorResData(CommonErrorCode.EXCEPTION));
    }
}
